package com.bjfu.staservice.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bjfu.common_utils.R;
import com.bjfu.staservice.entity.StatisticsDaily;
import com.bjfu.staservice.service.StatisticsDailyService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 网站统计日数据 前端控制器
 * </p>
 *
 * @author Guli
 * @since 2020-07-24
 */
@RestController
@RequestMapping("/staservice/daily")
//@CrossOrigin
public class StatisticsDailyController {
    @Autowired
    private StatisticsDailyService staService;

    @ApiOperation("统计注册人数")
    @PostMapping("register/{day}")
    public R countRegister(@PathVariable String day){
        QueryWrapper<StatisticsDaily> wrapper = new QueryWrapper<>();
        wrapper.eq("date_calculated",day);
        staService.countRegister(day);
        StatisticsDaily statisticsDaily = staService.getOne(wrapper);
        return R.ok().data("statisticsDaily",statisticsDaily);
    }

    @ApiOperation("图表显示")
    @GetMapping("showData/{type}/{begin}/{end}")
    public R showData(@PathVariable String type, @PathVariable String begin, @PathVariable String end){
        Map<String, Object> map = staService.getShowData(type,begin,end);
        return R.ok().data(map);
    }

}

